import Koa from 'koa';
import mount from 'koa-mount';
import body from 'koa-bodyparser';
import request from 'axios';

// Env settings
import env from '../../../conf.js';

// Mounts
import proxyApp from './mount/api.js';
import editorApp from './mount/editor.js';
import staticApp from './mount/static.js';

// Routes
import rootRouter from './routes/root.js';

const app = new Koa();

app.use(mount('/api', proxyApp));
app.use(mount('/editor', editorApp));
app.use(mount('/static', staticApp));

app.use(body())
    .use(rootRouter.routes())
    .use(rootRouter.allowedMethods());

app.listen(env.API_MAIN_PORT, () => {
    // 配置 axios 默认路径
    request.defaults.baseURL = `http://localhost:${env.API_MAIN_PORT}/`;
});